<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>COLOR TABLE</title>
		<script type="text/javascript" language="javascript">
			window.onload = function() {
				var tbl = document.getElementById("tbl");
				rows = tbl.getElementsByTagName("tr");
				var j = 0;
				/*for(i=0;i<rows.length;i++)
				{
					if(j>=2){
						rows[i].style.backgroundColor="yellow";
						if(j==3){
							j=-1;
						}
					}
					else{
						rows[i].style.backgroundColor="red";
					}
					j++;
				}*/
				/*原理:1组连续的数除以n整后得到数将会是每n个一组,且每组是一样的数,且奇偶相隔*/
				/*比如1组连续的数除以2,就会得到每2个一样的数奇偶相隔的出现一次*/
				/*0123456789*/
				/*除以2取整:0011223344*/
				/*除以3取整:000111222333444 以此类推 */
				for ( var i = 0; i < rows.length; i++) {
					j = parseInt(i / 2);
					if (j % 2 == 0) {
						rows[i].style.backgroundColor = "yellow";
					} else {
						rows[i].style.backgroundColor = "red";
					}
				}
			}
		</script>
	</head>
	<body>
		<a href="/test/index.jsp">首页</a>
	
		<hr color="red">
	
		<table id="tbl" border="1" bordercolor="green">
			<tr>
				<td>1</td>
				<td>1</td>
			</tr>
			<tr>
				<td>2</td>
				<td>2</td>
			</tr>
			<tr>
				<td>3</td>
				<td>3</td>
			</tr>
			<tr>
				<td>4</td>
				<td>4</td>
			</tr>
			<tr>
				<td>5</td>
				<td>5</td>
			</tr>
			<tr>
				<td>6</td>
				<td>6</td>
			</tr>
			<tr>
				<td>7</td>
				<td>7</td>
			</tr>
			<tr>
				<td>8</td>
				<td>8</td>
			</tr>
			<tr>
				<td>9</td>
				<td>9</td>
			</tr>
			<tr>
				<td>10</td>
				<td>10</td>
			</tr>
			<tr>
				<td>11</td>
				<td>11</td>
			</tr>
			<tr>
				<td>12</td>
				<td>12</td>
			</tr>
			<tr>
				<td>13</td>
				<td>13</td>
			</tr>
			<tr>
				<td>14</td>
				<td>14</td>
			</tr>
			<tr>
				<td>15</td>
				<td>15</td>
			</tr>
			<tr>
				<td>16</td>
				<td>16</td>
			</tr>
		</table>
	</body>
</html>